<?
	layout("/inc/layout.html",{title:sysTitle}){
?>

<div id="page-wrapper">
	<!--BEGIN TITLE & BREADCRUMB PAGE-->
	<div id="title-breadcrumb-option-demo" class="page-title-breadcrumb">
		<div class="page-header pull-left">
			<div class="page-title">数据备份</div>
		</div>
		<ol class="breadcrumb page-breadcrumb pull-left">
			<li><i class="fa fa-home"></i>&nbsp;<a href="main.html">首页</a>&nbsp;&nbsp;<i
				class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
			<li>大数据仓储&nbsp;&nbsp;<i class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
			<li class="active">数据备份</li>
		</ol>

		<div class="clearfix"></div>
	</div>
	<!--END TITLE & BREADCRUMB PAGE-->
	<!--BEGIN CONTENT-->
	<div class="page-content">

		<!-- 索引管理界面 start -->
		<div class="row">
			<div class="col-lg-12">
				<div class="note note-danger">
					<h3 class="box-heading">Tips</h3>
					<p>
		           	1、数据备份包括全库备份和增量备份，全库备份指备份该资源库所有的数据，增量备份指备份上次备份后新增的数据信息；建议初次备份使用全库备份，以后所有的备份采用增量备份；
		            </p>
		            <p>
		           	2、数据备份格式采用XML通用数据格式，大数据量支持多文件备份，统一提供压缩包下载方式；
		            </p>
		            <p>
		           	3、数据备份页面显示最近一次备份信息，如需要查看往期备份记录，请点击"查询所有数据备份记录"进行查询等操作；
		            </p>
		            <p>
		           	4、大数据量备份建议在系统空闲的时候进行操作；
		            </p>
				</div>
			</div>
		</div>
		<div class="row mbl">
		   <div class="col-lg-12">
           		<div class="tb-group-actions pull-right">
           			<button class="btn btn-sm btn-pink" onclick="importfrom2('0')">手动刷新</button>
           			<button class="btn btn-sm btn-success" onclick="importfrom2('1')">数据备份页面</button>
               		<button class="btn btn-sm btn-dark" onclick="importfrom2('2')">查询所有数据备份记录</button>
               </div>
           </div>
		</div>
		
		<div class="row" id="backup1">
			<div id="backup11">
			</div>
			<div id="backup12">
			</div>
		<!-- 
            <div class="col-lg-4">
                <div class="panel">
                    <div class="panel-heading clearfix"><span class="mts pull-left">期刊论文库（qk）</span>
                    </div>
                    <div class="panel-body">
	                    <p style="font-size: 15px;">
	                    		仓储库数据总量：99999
	                    </p>
	                    <p style="font-size: 15px;">
	                    		增量备份数据量：99999
	                    </p>
	                   	<p>
	                   		<button class="btn btn btn-grey" onclick="" style="width: 45%;">全库备份</button>
	                   		&nbsp;
	                   		<button class="btn btn btn-grey" onclick="" style="width: 45%;">增量备份</button>
	                   	</p>
	                   	<p style="font-size: 15px;color: #458B74;font-weight: bold;">
	                   		备份信息（最近一次）：
	                   	</p>
	                   	<p style="margin-left: 20px;">
	                   		数据总量：8888
	                   	</p>
	                   	<p style="margin-left: 20px;">
	                   		备份类型：增量备份
	                   	</p>
	                    <p style="margin-left: 20px;">
	                    		备份日期：2017-01-01 23:23:23
	                   	</p>
	                   	<p style="margin-left: 20px;">
	                   		备份文件：<button class="btn btn-sm btn-success" onclick="addproduct(0)">下载</button>
	                   	</p>
                    </div>
                </div>
            </div>
            <div class="col-lg-4">
                <div class="panel">
                    <div class="panel-heading clearfix"><span class="mts pull-left">期刊论文库（qk）</span>
                    </div>
                    <div class="panel-body">
                    <p style="font-size: 15px;">
                    		仓储库数据总量：99999
                    </p>
                    	<p style="font-size: 15px;">
                    		增量备份数据量：99999
                    </p>
                    	<p>
                    		<button class="btn btn btn-grey" onclick="" style="width: 45%;">全库备份</button>
                    		&nbsp;
                    		<button class="btn btn btn-grey" onclick="" style="width: 45%;">增量备份</button>
                    	</p>
                    	<p style="font-size: 15px;color: #458B74;font-weight: bold;">
                    		备份信息（最近一次）：
                    	</p>
                    	<p style="margin-left: 20px;">
                    		数据总量：8888
                    	</p>
                    	<p style="margin-left: 20px;">
                    		备份类型：增量备份
                    	</p>
                    <p style="margin-left: 20px;">
                    		备份日期：2017-01-01 23:23:23
                    	</p>
                    	<p style="margin-left: 20px;">
                    		备份文件：<button class="btn btn-sm btn-success" onclick="addproduct(0)">下载</button>
                    	</p>
                    </div>
                </div>
            </div>
            <div class="col-lg-4">
                <div class="panel">
                    <div class="panel-heading clearfix"><span class="mts pull-left">期刊论文库（qk）</span>
                    </div>
                    <div class="panel-body">
                    <p style="font-size: 15px;">
                    		仓储库数据总量：99999
                    </p>
                    	<p style="font-size: 15px;">
                    		增量备份数据量：99999
                    </p>
                    <p>
                    		<button class="btn btn btn-grey" onclick="" style="width: 45%;">全库备份</button>
                    		&nbsp;
                    		<button class="btn btn btn-grey" onclick="" style="width: 45%;">增量备份</button>
                    	</p>
                    	<p style="font-size: 15px;color: #458B74;font-weight: bold;">
                    		备份信息（最近一次）：
                    	</p>
                    	<p style="margin-left: 20px;">
                    		数据总量：8888
                    	</p>
                    	<p style="margin-left: 20px;">
                    		备份类型：增量备份
                    	</p>
                    <p style="margin-left: 20px;">
                    		备份日期：2017-01-01 23:23:23
                    	</p>
                    	<p style="margin-left: 20px;">
                    		备份文件：<button class="btn btn-sm btn-success" onclick="addproduct(0)">下载</button>
                    	</p>
                    </div>
                </div>
            </div>
            -->
        </div>
       <div class="row" id="backup2" hidden="hidden">
	       <div class="row mbl">
	           <div class="col-lg-6">
	          	   <button type="button"  class="btn btn-sm">选择分类：</button>
	               <select id="queryParams" class="btn btn-danger" style="width :140px;">
	                    <option value="-1">全部&nbsp;<span class="caret"></span></option>
	               </select>
	                   <button type="button" class="btn btn-sm btn-success" onclick="list1()">搜索</button>
	           </div>
	           <div class="col-lg-6">
	           <div class="tb-group-actions pull-right"><span>当前共<label id="pageSize"></label>条记录:</span>
	                   <select id="pageNumber" class="table-group-action-input form-control input-inline input-small input-sm mlm" onchange="list1()">
	                       <option value="5">5</option>
	                       <option value="10" >10</option>
	                       <option value="15" selected>15</option>
	                       <option value="25">25</option>
	                       <option value="50">50</option>
	                   </select>&nbsp;
	               </div>
	           </div>
	       </div>
              <table class="table table-hover table-striped table-bordered table-advanced tablesorter mbn">
            <thead>
                <tr>                 
                    <th >序号</th>
                    <th >知识库名称</th>
                    <th >英文名称</th>
                    <th >创建人</th>
                    <th >备份时间</th>
                    <th >备份类型</th>
                    <th >起始Id</th>
                    <th >结束Id</th>
                    <th >仓储库数据总量</th>
                    <th >备份数据量</th>
                    <th >状态</th>
                    <th >可操作</th>
                </tr>
            </thead>
            <tbody id="newspaperls"></tbody>
        </table>
        <div id="dataNull" class="panel-body"
				style="height: 90px; line-height: 50px;" align="center">
				<span class='subtitle' style="font-size: 15px;">数据为空!</span>
		</div>
        <div id="page1" style="text-align: center; margin-top: 20px;"></div>
        </div>
		<!-- 索引管理界面 end -->
	</div>
	 <input type="hidden" id="classesIds" value=""/>
	<!--END CONTENT-->
</div>
<?} ?>
<script>
var cur;
$(function (){
    cur=1;
	init();
	list1(cur);
});
function importfrom2(b){
	if(b == '1'){
		$("#backup2").hide();
		$("#backup1").show();
		init();
	}else if(b == '2'){
		$("#backup1").hide();
		$("#backup2").show();
		list1(1);
	}else if(b == '0'){
		init();
		list1(1);
	}
}
function list1(curr) {
	$.getJSON("./backupList.do",{
			page : curr || 1,
			queryParams : $("#queryParams").val(),
			pageNumber : $("#pageNumber").val()
	},
	function(res) {
			var str = '';
			var html='';
			if (res.listsize > 0) {
				$("#dataNull").hide();
			} else {
				$("#dataNull").show();
			}
			$("#newspaperls").html("");
			
			html += '<option value="-1">全部&nbsp;<span class="caret"></span>';
			for ( var i = 0; i < res.classes.length; i++) {
				html += '<option value="';
				html += res.classes[i].nameEn;
				html +='"';
				if($("#queryParams").val() == res.classes[i].nameEn){
					html += ' selected="selected"';
				}
				html += '>';
				html += res.classes[i].nameZh;
				
				html += '&nbsp;<span class="caret"></span></option>';
			}
			
			for ( var i = 0; i < res.listsize; i++) {
				str += "<tr><td align=\"center\"> "
				+ (i + 1)
				+ "</td><td> <label >";
				var split = res.result[i].classesEn.split(";");
				for(var k in split){
					for ( var j = 0; j < res.classes.length; j++) {
						if(split[k] == res.classes[j].nameEn){
							str += res.classes[j].nameZh + ";";
							break;
						}
					}
				}
				str += '</label></td><td><label >'
				+ res.result[i].classesEn
				+ '</label></td><td><label >'
				+ res.result[i].createUser
				+ '</label></td><td><label >'
				+ res.result[i].createTime
				+ '</label></td><td><label >'
				+ (res.result[i].type == '0'?'全库备份':'增量备份')
				+ '</label></td><td><label >'
				+ res.result[i].dataIdStart
				+ '</label></td><td><label >'
				+ res.result[i].dataIdEnd
				+ '</label></td><td><label >'
				+ res.result[i].repositoryCount
				+ '</label></td><td><label >'
				+ res.result[i].backupCount
				+ '</label></td><td>';
				if(res.result[i].status == '0'){
					str += '<button type="button" class="btn btn-blue btn-xs">备份中...</button>';
				}else{
					str += '<button type="button" class="btn btn-success btn-xs">备份完成</button>';
				}
				str += '</td><td>'
				+ '<button type="button" class="btn btn-default btn-xs" onclick="downBackup(\''+res.result[i].filePath+'\');">下载</button>'
				+ '</td></tr>';
				
				
			}
			$("#newspaperls").html(str);
			$("#queryParams").html(html);
		laypage({
			cont : document.getElementById('page1'), //容器。值支持id名、原生dom对象，jquery对象,
			pages : res.pageSize, //总页数
			skip : true, //是否开启跳页
			skin : 'molv', //加载内置皮肤，也可以直接赋值16进制颜色值，如:#c00
			curr : curr || 1,
			last : res.pageSize,
			groups : 6,//连续显示分页数
			jump : function(obj, first) { //触发分页后的回调
				if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
					list1(obj.curr);
					var curr = obj.curr;
					curr = obj.curr;
				}
			}
		});
	});
}
function init(){
	$.ajax({
		type : "post",
		url : "./initbackup.do",
		dataType : "json",
		success : function(rel) {
			var d = eval(rel);
			var html = '';
			var html1 ='';
			var data = d[0].list;
			var cus = d[0].customize;
			for(var i = 0; i< data.length; i++){
				html += '<div class="col-lg-4">';
				html += '<div class="panel">';
				html += '<div class="panel-heading clearfix"><span class="mts pull-left">';
				html += data[i].clazz.nameZh;
				html += '(';
				html += data[i].clazz.nameEn;
				html += ')';
				html += '</span>';
				html += '</div>';
				html += '<div class="panel-body" style="height:300px;">';
				/* html += '<p style="font-size: 15px;">仓储库数据总量：';
				html += data[i].count;
				html += '</p>';
				html += '<p style="font-size: 15px;">增量备份数据量：';
				html += data[i].zcount;
				html += '</p>'; */
				html += '<p>';
				html += '<button class="btn btn btn-grey" onclick="backup(\''+ data[i].clazz.nameEn +'\',0);" style="width: 45%;">全库备份</button>';
				html += '&nbsp;';
				html += '<button class="btn btn btn-grey" onclick="backup(\''+ data[i].clazz.nameEn +'\',1);" style="width: 45%;">增量备份</button>';
				html += '</p>';
				html += '<p style="font-size: 15px;color: #458B74;font-weight: bold;">备份信息（最近一次）：</p>';
	            html += '<p style="margin-left: 20px;">数据总量：';	
	            html += data[i].dataBackup.backupCount==undefined?'0':data[i].dataBackup.backupCount;       		
	            html += '</p>';
	            html += '<p style="margin-left: 20px;">备份类型：';
	            html += data[i].dataBackup.type==undefined?'无':(data[i].dataBackup.type == '0'?'全库备份':'增量备份');
	            html += '</p>';   	
	            html += '<p style="margin-left: 20px;">备份日期：';      	
	            html += data[i].dataBackup.createTime==undefined?'无':data[i].dataBackup.createTime;
	            html += '</p>';
	            html += '<p style="margin-left: 20px;">备份文件：';  
	            if(data[i].dataBackup.status!=undefined){
		            if(data[i].dataBackup.status=='1'){
		             	html += '<button class="btn btn-sm btn-success" onclick="downBackup(\''+ data[i].dataBackup.filePath +'\')">';
			            html += '下载';
			            html += '</button>';
		            }
	            }else{
	            	html += '&nbsp;<button class="btn btn-sm btn-success" id="'+data[i].clazz.nameZh+'_backup">无</button>';
	            }
	            if(data[i].dataBackup.status!=undefined){
	             	html += '&nbsp;<button class="btn btn-sm btn-success" id="'+data[i].clazz.nameZh+'_backup">';
	            	html += data[i].dataBackup.status=='0'?'备份中...':'备份完成';
	            	html += '</button>';
	            }
	            html += '</p>';
	            html += '</div>';
	            html += '</div>';
	            html += '</div>';
			}
			html1 += '<div class="col-lg-4"><div class="panel">';
			html1 += '<div class="panel-heading clearfix"><span class="mts pull-left">自定义备份</span></div>';
			html1 += '<div class="panel-body" style="height:300px;"><p>';
			html1 += '<div class="row">';
			html1 += '<div class="col-lg-4">';
			html1 += ' &nbsp; <button class="btn btn btn-grey" onclick="customizeBackup();">选择知识库</button>';
			html1 += '</div>';
			html1 += '<div class="col-lg-8">';
			html1 += '<div style="width:100%;overflow:auto;max-height: 70px;background-color: #f0f2f5;" id="selectIds"> ';
			/* html1 += '<button class="btn btn btn-blue btn-xs" onclick="" style="margin-top: 3px;" >这里显示您选择知识库</button>'; */
			html1 += '</div></div></div>';
			html1 += '</p><p>';
			html1 += '&nbsp;<button class="btn btn btn-grey" onclick="customize(\'0\');" style="width: 45%;">全库备份</button>';
			html1 += '&nbsp;<button class="btn btn btn-grey" onclick="customize(\'1\');" style="width: 45%;">增量备份</button>';
			html1 += '</p><p style="font-size: 15px;color: #458B74;font-weight: bold;">备份信息（最近一次）：</p>';
			html1 += '<p style="margin-left: 20px;">备份类型：';
			html1 += (cus[0] == undefined?'无':cus[0].type == '0'?'全库备份 ':'增量备份');
			html1 += '</p><p style="margin-left: 20px;">备份日期：';
			html1 += (cus[0] == undefined?'无':cus[0].createTime);
			html1 += '</p><p style="margin-left: 20px;">备份文件：';
			if(cus[0]!=undefined){
			 	if(cus[0].status=='1'){
		             html1 += '<button class="btn btn-sm btn-success" onclick="downBackup(\''+cus[0].filePath +'\')">';
			         html1 += '下载';
			         html1 += '</button>';
		         }
			}else{
				html1 += '<button class="btn btn-sm btn-success" id="customize_backup" onclick="addproduct(0)">无</button>';
			}
			if(cus[0]!=undefined){
	       		html1 += '&nbsp;<button class="btn btn-sm btn-success" id="customize_backup">';
	        	html1 += cus[0].status=='0'?'备份中...':'备份完成';
	       		html1 += '</button>';
	        }
			html1 += '</p></div></div></div>';
			$("#backup12").html(html);
			$("#backup11").html(html1);
		},
		error : function(data) {
		}
	});
}
//0：全量，1：增量
function backup(classesEn,allOrZeng){
	if (confirm("确认开始备份，刷新页面查看状态！")){
		$("#"+classesEn+"_backup").text("备份中...");
		$.ajax({
			type : "post",
			url : "./backup.do",
			data : {
				"classesEn":classesEn,
				"allOrZeng":allOrZeng,
			},
			dataType : "json",
			async:true, 
			success : function(rel) {
				if(rel[0].info == 'success'){
					$("#"+classesEn+"_backup").text("备份完成");
					alert("备份成功！");
					init();
				}
			},
			error : function(data) {
			}
		});
	}
}
function downBackup(filePath){
	var url='./downBackup.do?filePath='+filePath;
	window.location.href=url;
}
function customizeBackup(){
		layer.open({
			type : 2,
			area : [ '500px', '350px' ],
			scrollbar : true,
			shadeClose : true,
			fix : false, //不固定
			title : '选择知识库',
			//maxmin : true,  
			skin : 'layui-layer-rim', //加上边框
			btn : [ '选择','关闭'],
			content : [ "data-handling-customize.html?winName="+window.name, 'yes' ],
			yes : function(index, layer) {
				var iframeWin = parent.window[layer.find('iframe')[0]['name']];
				iframeWin.start();
				getClasses();
			},cancel : function(index) {
			}
		});
}
function customize(allOrZeng){
	if($("#classesIds").val() == ''){
		alert("请选择备份知识库");
		return;
	}
	if (confirm("确认开始备份，刷新页面查看状态！")){
		$("#customize_backup").text("备份中...");
		$.ajax({
			type : "post",
			url : "./customize.do",
			data : {
				"allOrZeng":allOrZeng,
				"classesIds":$("#classesIds").val(),
			},
			dataType : "json",
			async:true, 
			success : function(rel) {
				if(rel[0].info == 'success'){
					$("#customize_backup").text("备份完成");
					alert("备份成功！");
					init();
				}
			},
			error : function(data) {
			}
		});
	}
}
function getClasses(){
	$.ajax({
		type : "post",
		url : "./getClasses.do",
		data : {
			"classesIds":$("#classesIds").val(),
		},
		dataType : "json",
		async:true, 
		success : function(rel) {
			var html = '';
			for(var i = 0;i<rel.length;i++){
				html += ' <button class="btn btn btn-blue btn-xs" onclick="" style="margin-top: 3px;" >';
				html += rel[i].nameZh
				html += '</button>';
				
			}
			$("#selectIds").html(html);
		},
		error : function(data) {
		}
	});
}
</script>